<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * Copyright (C) 2007  Robert Moss
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

?>
<script type="text/javascript">
// <![CDATA[
<!--
function ajaxevents(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('eventscontainer').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function squads(matchid) {
		var homeobj = document.getElementById("homesqad");
   	var homeopts = homeobj.options;
   	var homestring = "";
   	for (i=0; i<homeopts.length; i++)   {
    	if (homeopts[i].selected == true) { homestring += homeopts[i].value+";"; }
   	}
   	var awayobj = document.getElementById("awaysqad");
   	var awayopts = awayobj.options;
   	var awaystring = "";
   	for (i=0; i<awayopts.length; i++)   {
    	if (awayopts[i].selected == true) { awaystring += awayopts[i].value+";"; }
   	}
   	var poststr = "option=com_joomleague&func=editEvents&mytask=savesquads" +
   	"&p=" + encodeURI( document.getElementById("p").value ) +
   		"&mid=" + encodeURI( document.getElementById("match_id").value ) +
   		"&home=" + encodeURI( homestring ) +
   		"&away=" + encodeURI( awaystring ) +
   		"&no_html=1";
   	makePOSTRequest('index2.php', poststr);
   }
   function get(obj) {
      var poststr = "option=com_joomleague&func=editEvents&mytask=saveevent" +
      							"&p=" + encodeURI( document.getElementById("p").value ) +
      							"&event_type_id=" + encodeURI( document.getElementById("event_type_id").value ) +
                    "&notice=" + encodeURI( document.getElementById("notice").value ) +
                    "&event_sum=" + encodeURI( document.getElementById("event_sum").value ) +
                    "&mid=" + encodeURI( document.getElementById("match_id").value ) +
                    "&event_time=" + encodeURI( document.getElementById("event_time").value ) +
                    "&no_html=1";
      if (document.getElementById("hometeam").disabled==false) poststr += "&player_id=" + encodeURI(document.getElementById("hometeam").value) ;
      if (document.getElementById("guestteam").disabled==false) poststr += "&player_id=" + encodeURI(document.getElementById("guestteam").value) ;
      makePOSTRequest('index2.php', poststr);
   }

   function update(obj) {
   	var formname = obj;
   	var playerid = formname.player_id.value;
   	var evtypeid = formname.event_type_id.value;
   	var evid  = formname.evid.value;
   	var evtime = formname.event_time.value;
   	var eventnotice = formname.notice.value;
   	var event_sum = formname.event_sum.value;
      var poststr = "option=com_joomleague&func=editEvents&mytask=updateevent" +
							      "&p=" + encodeURI( document.getElementById("p").value ) +
							      "&mid=" + encodeURI( document.getElementById("match_id").value ) +
							      "&event_type_id=" + encodeURI( evtypeid ) +
							      "&player_id=" + encodeURI( playerid ) +
							      "&notice=" + encodeURI( eventnotice ) +
							      "&event_sum=" + encodeURI( event_sum ) +
							      "&event_time=" + encodeURI( evtime ) +
							      "&evid=" + encodeURI( evid ) +
							      "&no_html=1";
      makePOSTRequest('index2.php', poststr);
    }
/***Combo Menu Load Ajax snippet**/
function ajaxcombo(selectobjID, loadarea){
var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
ajaxevents(selectobj.options[selectobj.selectedIndex].value, loadarea)
}
//-->
// ]]>
</script>
